<?php 

Class appModel extends Model
{
	public function get_app()
	{
// 		$arr=array();
// 		$sql="SELECT op_value FROM ".$this->table('options')." WHERE op_key='appid' OR op_key='appsecret'";
// 		$temp=$this->getAll($sql);
		$arr['appid']="wxc59074e82da37239";
		$arr['appsecret']="c6cb2b54e28e38dd7cff2d426460303c";
		return $arr;
	}
	public function get_cfg($key='')
	{
		if($key)
		{
			$sql="SELECT op_value FROM ".$this->table('options')." WHERE op_key='".$key."'";
			$arr=$this->getOne($sql);
			
		}
		else 
		{
		   $sql="SELECT * FROM ".$this->table('options')." ";
		   $arr=array();
		   $res=$this->getAll($sql);
		   
		   if(count($res)>0)
		  {
			  foreach($res as $k=>$v)
			  {
				$arr[$v['op_key']]=$v['op_value'];
			  }
		   }
		}
		
		return $arr;
	}
	
	public function get_count_openid($openid)
	{
		$sql = "select count(*) from ".$this->table('wxusers')." where openid='".$openid."'";
		return $this->getOne($sql);
	}
	
	public function get_wxid($openid)
	{
		$sql = "select wxid from ".$this->table('wxusers')." where openid='".$openid."'";
		return $this->getOne($sql);
	}
	
	public function get_openid($wxid){
		$sql = "select openid from ".$this->table('wxusers')." where wxid='".$wxid."'";
		return $this->getOne($sql);
	}
	public function insert_into_wxuser($info)
	{
		$data = yf_set_insert($info);
		$sql = "insert into ".$this->table('wxusers')." (".$data['key'].") values (".$data['val'].")";
		if($this->query($sql))
		{
			return $this->insert_id();
		}
		else
		{
			return false;
		}
	}
}